package com.wjcxf.guonianla;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.wjcxf.guonianla.service.MusicService;
import com.wjcxf.guonianla.view.MainFragment;

public class MainActivity extends AppCompatActivity {
    Context mContext;

    private MusicService mMusicService ;

    public MusicService getmMusicService(){
        return mMusicService;
    }
    private ServiceConnection conn = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder binder) {
            MusicService.MusicBinder  myBinder = (MusicService.MusicBinder)binder;
            mMusicService = myBinder.getService();

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //兼容老版本
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        //初始化fragment
        MainFragment mainFragment = new MainFragment();
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.main_frame_layout,mainFragment);
        transaction.commit();

        mContext = this;

        //绑定音频Service
        Intent musicIntent = new Intent();
        musicIntent.setClass(getApplicationContext(), MusicService.class);
        bindService(musicIntent, conn, BIND_AUTO_CREATE);
    }
}
